//
//  LZSOneCell.m
//  IOSProject
//
//  Created by lzs on 2018/4/18.
//  Copyright © 2018年 com.linzhisheng. All rights reserved.
//

#import "LZSOneCell.h"

@interface LZSOneCell()

@property (nonatomic, strong) UIImageView *iconImageView;


@end

@implementation LZSOneCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
        self.iconImageView.backgroundColor = [UIColor whiteColor];
        self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.iconImageView.clipsToBounds = YES;
        self.iconImageView.layer.cornerRadius = 3;
        self.iconImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.iconImageView];
        
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).mas_offset(15);
            make.left.equalTo(self.contentView).mas_offset(15);
            make.size.mas_equalTo(CGSizeMake(80, 80));
            make.bottom.equalTo(self.contentView.mas_bottom).mas_equalTo(-15);
        }];
        
        self.titleLabel = [self setuplabelwithfont:[UIFont systemFontOfSize:15] withText:@"独守空房了肯定是咖啡店金石可镂局付款了第三方卡兰蒂斯" withColor:[UIColor blackColor] wihtAlignemt:NSTextAlignmentLeft];
        self.titleLabel.numberOfLines = 2;
        self.titleLabel.preferredMaxLayoutWidth = 200;
        [self.contentView addSubview:self.titleLabel];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.mas_top).mas_offset(15);
            make.left.equalTo(self.iconImageView.mas_right).mas_offset(15);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-80);
        }];
        
        self.timeLabel = [self setuplabelwithfont:[UIFont systemFontOfSize:15] withText:@"2018-04-22" withColor:[UIColor blackColor] wihtAlignemt:NSTextAlignmentLeft];
        self.timeLabel.numberOfLines = 2;
        self.timeLabel.preferredMaxLayoutWidth = 200;
        [self.contentView addSubview:self.timeLabel];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(15);
            make.left.equalTo(self.iconImageView.mas_right).mas_offset(15);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-80);
        }];
        
        self.btn = [self setupbtnWithFont:[UIFont systemFontOfSize:15] withText:@"收藏" withColor:[UIColor blackColor] wihtAlignemt:NSTextAlignmentCenter];
        self.btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.btn.layer.borderWidth = 0.5;
        self.btn.layer.cornerRadius = 3;
        self.btn.layer.masksToBounds = YES;
        [self.contentView addSubview:self.btn];
        
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.iconImageView.mas_centerY);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-15);
            make.size.mas_equalTo(CGSizeMake(60, 30));
        }];
    }
    return self;
}

-(void)setListmodel:(LZSListModel *)Listmodel{
    _Listmodel = Listmodel;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:Listmodel.pic] placeholderImage:[UIImage imageNamed:@"default.png"] options:(SDWebImageRetryFailed)];
    self.titleLabel.text = Listmodel.title;
    self.timeLabel.text = Listmodel.time;
}
-(UILabel *)setuplabelwithfont:(UIFont *)font withText:(NSString *)text withColor:(UIColor *)color wihtAlignemt:(NSTextAlignment)textalignment{
    UILabel *label = [[UILabel alloc] init];
    label.text = text;
    label.font = font;
    label.textAlignment = textalignment;
    label.textColor = color;
    return label;
}

-(UIButton *)setupbtnWithFont:(UIFont *)font withText:(NSString *)text withColor:(UIColor *)color wihtAlignemt:(NSTextAlignment)textalignment{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:text forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font = font;
    btn.titleLabel.textAlignment = textalignment;
    
    return btn;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
